<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn">点击抽奖</button>
</body>
<script>
    function rand(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min
    }
    const btn = document.querySelector('.btn')
    btn.addEventListener('click', function () {
        var p = new Promise((resolve, reject) => {
            setTimeout(() => {
                let n = rand(1, 100)
                if (n <= 30) {
                    resolve(n)
                } else {
                    reject(n)
                }
            }, 1000);
        })
        console.log(p);
        p.then((value) => {
            alert('恭喜您中奖了，中奖的数字为 '+ value)
        }, (reason) => {
            alert('遗憾，数字为' + reason)
        })
    })
</script>

</html>